using System;
using System.Collections.Generic;
using System.Text;

namespace TTBox
{
public class SerialData
{
    // Fields
    private GPSData vGPSData = new GPSData();

    // Methods
    public bool ParseFrame(ref byte[] bytePosFrame)
    {
        bool flag = false;
        string[] strArray = null;
        string s = "";
        string str3 = "";
        string str4 = "";
        string str5 = "";
        string str6 = "";
        string str7 = "";
        string str8 = "";
        string message = "";
        try
        {
            strArray = Encoding.ASCII.GetString(bytePosFrame, 0, bytePosFrame.Length).TrimEnd(new char[1]).Split(new char[] { ',' });
            if (strArray == null)
            {
                return flag;
            }
            s = "A0A100" + GPSData.posFrameId;
            str3 = strArray[9];
            str4 = strArray[1].Substring(0, strArray[1].IndexOf("."));
            str5 = (str3.Substring(4, 2) + str3.Substring(2, 2) + str3.Substring(0, 2)) + str4;
            GPSData.dt = str5;
            s = s + str5;
            GPSData.gpsFix = strArray[2];
            double num = 0.0;
            str7 = strArray[3];
            if (str7 != "")
            {
                this.vGPSData.latInd = strArray[4];
                str6 = str7.Substring(0, 2);
                num = Convert.ToDouble(str7.Remove(0, 2)) / 60.0;
                str7 = Convert.ToString(num);
                str7 = str6 + str7.Substring(str7.IndexOf("."));
                this.vGPSData.lat = Convert.ToDouble(str7);
                if (this.vGPSData.latInd == "N")
                {
                    num = Convert.ToDouble(str7) * 1000000.0;
                }
                else if (this.vGPSData.latInd == "S")
                {
                    num = 180.0 - (Convert.ToDouble(str7) * 1000000.0);
                }
                str7 = Convert.ToString(Convert.ToInt32(num), 0x10);
                if (str7.Length > 8)
                {
                    str7 = str7.Substring(0, 8);
                }
                else if (str7.Length < 8)
                {
                    str7 = str7.PadLeft(8, '0');
                }
            }
            else
            {
                str7 = "00000000";
            }
            GPSData.strLatPos = str7;
            s = s + str7;
            str8 = strArray[5];
            if (str8 != "")
            {
                this.vGPSData.lonInd = strArray[6];
                str6 = str8.Substring(0, 3);
                num = Convert.ToDouble(str8.Remove(0, 3)) / 60.0;
                str8 = Convert.ToString(num);
                str8 = str6 + str8.Substring(str8.IndexOf("."));
                this.vGPSData.lon = Convert.ToDouble(str8);
                if (this.vGPSData.lonInd == "E")
                {
                    num = Convert.ToDouble(str8) * 1000000.0;
                }
                else if (this.vGPSData.lonInd == "W")
                {
                    num = 360.0 - (Convert.ToDouble(str8) * 1000000.0);
                }
                str8 = Convert.ToString(Convert.ToInt32(num), 0x10);
                if (str8.Length > 8)
                {
                    str8 = str8.Substring(0, 8);
                }
                else if (str8.Length < 8)
                {
                    str8 = str8.PadLeft(8, '0');
                }
            }
            else
            {
                str8 = "00000000";
            }
            GPSData.strLonPos = str8;
            s = (s + str8) + GPSData.gpsFix + "00000";
            if (GPSData.TaxiStationId.Length < 3)
            {
                s = s + GPSData.TaxiStationId.PadLeft(3, '0');
            }
            else
            {
                s = s + GPSData.TaxiStationId;
            }
            if (GPSData.TaxiQueueNumber.Length < 3)
            {
                s = s + GPSData.TaxiQueueNumber.PadLeft(3, '0');
            }
            else
            {
                s = s + GPSData.TaxiQueueNumber;
            }
            if (GPSData.isAvailable)
            {
                s = s + "1";
            }
            else
            {
                s = s + "0";
            }
            s = s + "B2B3";
            message = Convert.ToString(s.Substring(8, s.Length - 12).Length, 0x10);
            if (message.Length == 1)
            {
                message = "0" + message;
            }
            s = s.Remove(4, 2).Insert(4, message);
            bytePosFrame = Encoding.ASCII.GetBytes(s);
            flag = true;
        }
        catch (Exception exception)
        {
            message = exception.Message;
        }
        finally
        {
            s = "";
            str3 = "";
            str4 = "";
            str5 = "";
            str6 = "";
            str7 = "";
            str8 = "";
            message = "";
            strArray = null;
            GC.Collect();
        }
        return flag;
    }
}

 


}
